
/**
 * Wrapper class to allow capture of the number of calls to compareTo.
 *
 * @author   Timothy Rolfe
 * @see        "No borrowed code"
 */
public class MyComparable implements Comparable
{
   private static long count = 0;

   private Comparable value;

   public MyComparable ( Comparable item )
   {  value = item;  }

/**
 * Provide access to the value.
 *
 * @return     the result of item.toString()
 * @exception  none  no exception thrown
 * @see        "No borrowed code"
 */
   public Comparable getValue()
   {  return value;  }

/**
 * Provide access to the appropriate toString method.
 *
 * @return     the result of item.toString()
 * @exception  none  no exception thrown
 * @see        "No borrowed code"
 */
   public String toString()
   {  return value.toString();  }

/**
 * Count up the number of calls, then return the result of the compareTo.
 *
 * @param     o  Generic object as the right operand in the comparison
 * @return    an integer with the result of the comparison
 * @exception none  no exception thrown
 * @see       "No borrowed code"
 */
   public int compareTo(Object o)
   {  MyComparable rt = (MyComparable)o;

      count++;
      return value.compareTo(rt.value);
   }

/**
 * Return the result of the compareTo WITHOUT counting it in.  This can
 * be used if there are utility routines that need to make comparisons
 * but their comparisons should not be included in the statistics.
 *
 * @param     o  Generic object as the right operand in the comparison
 * @return    an integer with the result of the comparison
 * @exception none  no exception thrown
 * @see       "No borrowed code"
 */
   public int freeCompare(Comparable o)
   {
      MyComparable rt = (MyComparable)o;

      return value.compareTo(rt.value);
   }

/**
 * Zero out the counter, and return the number of compareTo calls.
 *
 * @return     long giving the number of compareTo calls
 * @exception  none  no exception thrown
 * @see        "No borrowed code"
 */
   static public long nCompares()
   {
      long hold = count;

      count = 0;
      return hold;
   }
}

